<template>
  <div>
    echarts测试页面
    <!-- 创建div当做echarts渲染的容器 -->
    <div id="container" style="width: 500px; height: 500px"></div>
  </div>
</template>
<script>
//引入echarts
import * as echarts from "echarts";
export default {
  // mounted() {
  //   this.initEcharts();
  // },
  methods: {
    //渲染数据到echarts中的函数
    initEcharts() {
      //echarts配置
      var option = {
        title: {
          text: "Referer of a Website",
          subtext: "Fake Data",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: "50%",
            data: [
              { value: 1048, name: "Search Engine" },
              { value: 735, name: "Direct" },
              { value: 580, name: "Email" },
              { value: 484, name: "Union Ads" },
              { value: 300, name: "Video Ads" },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      //查找页面中的容器
      var chartDom = document.getElementById("container");
      //echarts绑定容器
      var myChart = echarts.init(chartDom);
      //echarts使用上面的配置渲染
      myChart.setOption(option);
    },
  },
};
</script>
